const EalenToken = artifacts.require("EalenToken.sol");
const Exchange = artifacts.require("Exchange.sol");
const ETH_ADDRESS = "0x0000000000000000000000000000000000000000";

const fromWei = bn => {
    return web3.utils.fromWei(bn, "ether");
};

const toWei = number => {
    return web3.utils.toWei(number.toString(), "ether");
};

const wait = (seconds) => {
    const milliseconds = seconds * 1000;
    return new Promise(resolve => setTimeout(resolve, milliseconds));
}

module.exports = async function (callback) {
    try {
        const token = await EalenToken.deployed();
        const exchange = await Exchange.deployed();
        const accounts = await web3.eth.getAccounts();

        for (let i = 1; i <= 5; i++) {
            await exchange.makeOrder(token.address, toWei(100 + i), ETH_ADDRESS, toWei(i / 1000), {
                from: accounts[0]
            })
            console.log(`account[0]制作第${i}个订单`);
            await wait(1);
        }

        for (let i = 1; i <= 5; i++) {
            await exchange.makeOrder(token.address, toWei(1000 + i), ETH_ADDRESS, toWei(i / 100), {
                from: accounts[1]
            })
            console.log(`account[1]制作第${i}个订单`);
            await wait(1);
        }
    } catch (error) {
        console.log(error);
    }
    callback();
}